<?php

$api = app('Dingo\Api\Routing\Router');

use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Admin\CategoryController;
use App\Http\Controllers\Admin\GoodsController;
$params = [
    'middleware' => [
        'api.throttle',
        'serializer:array', //减少transformer包裹层
        'bindings' // 支持路由模型注入
    ],
    'limit' => 60,
    'expires' => 1
];

$api->version('v1', $params, function($api){

    $api->group(['prefix'=>'admin'], function($api){
        //需要登录的路由
        $api->group(['middleware' => 'api.auth'], function($api){

            // 用户禁用/启用
            $api->patch('users/{user}/lock', [UserController::class, 'lock']);
            // 用户资源路由
            $api -> resource('users', UserController::class, ['index', 'show']);

            //分类-禁用/启用
            $api->patch('category/{category}/status', [CategoryController::class, 'status']);
            //分类管理
            $api->resource('category', CategoryController::class, ['except'=>['destory']]);
            //分类列表
            $api->resource('category', CategoryController::class, ['index']);

            // 是否上架
            $api->patch('goods/{good}/on', [GoodsController::class, 'is_on']);
            // 是否推荐
            $api->patch('goods/{good}/recommend', [GoodsController::class, 'is_recommend']);
            // 商品管理资源路由
            $api->resource('goods', GoodsController::class, ['except'=>['destory']]);
        });
    });
});
